package cn.edu.neusoft.maxingxin231.yuejian06.Adapter;

import android.content.Context;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.squareup.picasso.Picasso;

import java.util.List;

import cn.edu.neusoft.maxingxin231.yuejian06.Activity.AttListActivity;
import cn.edu.neusoft.maxingxin231.yuejian06.Activity.ClubDetail;
import cn.edu.neusoft.maxingxin231.yuejian06.Activity.DetailActivity;
import cn.edu.neusoft.maxingxin231.yuejian06.Bean.AttListBean;
import cn.edu.neusoft.maxingxin231.yuejian06.Bean.ClubBean;
import cn.edu.neusoft.maxingxin231.yuejian06.R;

public class AttListAdapter extends RecyclerView.Adapter<ClubViewHolder>{
    private View view = null;
    private Context context;
    private RecyclerView recyclerView;
    private RecyclerView.LayoutManager layoutManager;
    private LayoutInflater layoutInflater;//动态加载布局
    private  List<AttListBean> list;
    private String md;
    String id,club_name,club_address;
    String user_id;

    public AttListAdapter(Context context){
        this.context=context;
        layoutInflater=LayoutInflater.from(context);
    }
    public AttListAdapter(Context context,String mod) {
        this.context=context;
        this.md=mod;
        layoutInflater=LayoutInflater.from(context);
    }


    @NonNull
    @Override
    public ClubViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View v=LayoutInflater.from(parent.getContext()).inflate(R.layout.club_card,parent,false);
        return new ClubViewHolder(v);
    }

    @Override
    public void onBindViewHolder(@NonNull ClubViewHolder holder, int position) {
        final AttListBean attListBean=list.get(position);
        if(attListBean==null) return;
        final String club_id=attListBean.getClub_id();
        ClubViewHolder clubViewHolder=(ClubViewHolder)holder;
        clubViewHolder.c_tv1.setText(attListBean.getClub_name());
        clubViewHolder.c_tv2.setText(attListBean.getClub_address());
        Picasso.with(context).load("http://10.0.2.2/yuejian14/public/static/club_img/"+attListBean.getClub_pic()).into(clubViewHolder.c_img1);

        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(context, ClubDetail.class);
                intent.putExtra("club_id",club_id);
                intent.putExtra("club_pic",attListBean.getClub_pic());
                intent.putExtra("club_name",attListBean.getClub_name());
                intent.putExtra("club_address",attListBean.getClub_address());
                intent.putExtra("club_intro",attListBean.getClub_intro());
                //intent.putExtra("fans_type")
                context.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        if(list==null){
            return 0;
        }
        else
            return list.size();
    }

    //2自定义：获取数据
    public void setList(List<AttListBean> list)
    {
        this.list=list;
        notifyDataSetChanged();
    }
    //3自定义：ViewHolder子类


}
